const baseurl = "http://testoa.htinfor.com:10088"


const formDataRequest = (options) => {
	// 
	let dataObject = {};
	for (let pair of options.data.entries()) {
		dataObject[pair[0]] = pair[1];
	}

	return new Promise((resolve, reject) => {
		if (options.method == "GET") {
			uni.request({
				url: `${baseurl}${options.url}`,
				data: options.data,
				method: options.method,
				success: (res) => {
					return resolve(res.data)
				},
				fail: (error) => {
					return reject(error)
				}
			});
		}
		if (options.method == "POST") {
			uni.request({
				url: `${baseurl}${options.url}`,
				data: dataObject,
				method: options.method,
				header: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				success: (res) => {
					return resolve(res.data)
				},
				fail: (error) => {
					return reject(error)
				}
			});
		}
	})
}

export default formDataRequest